﻿using System;
using System.Configuration;
using System.Data;
using System.Globalization;

using BizElements.Core;

namespace BizElements.BusinessLayer
{
    /// <summary>
    /// <see cref="LockManager"/> specialization for scenario where lock info and objects are contained in the same database table.
    /// </summary>
    [Serializable]
    public sealed class SelfLockManager : LockManager
    {
        /// <summary>
        /// Initializes a new instance of SelfLockManager class.
        /// </summary>
        /// <param name="table">Table which contains lock information and objects which are being locked.</param>
        /// <param name="lockedByColumn">Nullable database field which contains the <see cref="IActor.Id"/> of <see cref="IActor"/> which locked the object.</param>
        /// <param name="lockedTillColumn">Nullable datetime database field which specifies when the lock expires.</param>
        /// <param name="lockModeColumn">Optional nullable database column which indicates whether the object is exlusively locked.</param>
        public SelfLockManager(IDbTable table, IDbColumn lockedByColumn, IDbColumn lockedTillColumn, IDbColumn lockModeColumn)
            : base(table, null, table.PrimaryKey.ToArray(), lockedByColumn, lockedTillColumn, lockModeColumn, false, null, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of SelfLockManager class.
        /// </summary>
        /// <param name="table">Table which contains lock information and objects which are being locked.</param>
        /// <param name="lockedByColumn">Nullable database field which contains the <see cref="IActor.Id"/> of <see cref="IActor"/> which locked the object.</param>
        /// <param name="lockedTillColumn">Nullable datetime database field which specifies when the lock expires.</param>
        /// <param name="lockModeColumn">Optional nullable database column which indicates whether the object is exlusively locked.</param>
        /// <param name="exclusiveLockIsDefault">Indicates whether exclusive locks are used by default.</param>
        /// <param name="exclusiveLockIndicator">The value which, when inserted into <b>lockModeColumn</b>, indicates that the object is locked exclusively.</param>
        /// <param name="sharedLockIndicator">The value which, when inserted into <b>lockModeColumn</b>, indicates that the object is locked for writing, but available for reading.</param>
        public SelfLockManager(IDbTable table, IDbColumn lockedByColumn, IDbColumn lockedTillColumn, IDbColumn lockModeColumn, bool exclusiveLockIsDefault, object exclusiveLockIndicator, object sharedLockIndicator)
            : base(table, null, table.PrimaryKey.ToArray(), lockedByColumn, lockedTillColumn, lockModeColumn, exclusiveLockIsDefault, exclusiveLockIndicator, sharedLockIndicator)
        {
        }
    }
}